summaryrefslogtreecommitdiff
path: root/src/pages/blog/[...year].astro
diff options
context:
space:
mode:
authorJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-28 18:14:22 -0300
committerJoão Augusto Costa Branco Marado Torres <torres.dev@disroot.org>2025-06-28 18:14:22 -0300
commit79fd506d30eef3d113f4a8e3ab9ebd9004f1e8cc (patch)
tree96ff57c92e897c3cc3331e23043d20f1665c7d0a /src/pages/blog/[...year].astro
parenta1eac976b20e39f86d5944fbec68e2a0f8ffb746 (diff)
feat: index page
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/pages/blog/[...year].astro')
-rw-r--r--src/pages/blog/[...year].astro30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/pages/blog/[...year].astro b/src/pages/blog/[...year].astro
index f148a76..1742baa 100644
--- a/src/pages/blog/[...year].astro
+++ b/src/pages/blog/[...year].astro
@@ -1,20 +1,16 @@
---
+import type {
+ GetStaticPaths,
+ InferGetStaticParamsType,
+ InferGetStaticPropsType,
+} from "astro";
import { getCollection } from "astro:content";
-import type { CollectionEntry } from "astro:content";
import Base from "@layouts/Base.astro";
import DateSelector from "@components/DateSelector.astro";
import BlogCard from "@components/BlogCard.astro";
+import { sortLastCreated } from "@lib/collection/helpers";
-type Props = {
- posts: CollectionEntry<"blog">[];
- next: string;
- previous: string;
- years: number[];
- months: number[];
- days?: number[];
-};
-
-export async function getStaticPaths() {
+export const getStaticPaths = (async () => {
const posts = await getCollection("blog");
const archive = {
@@ -128,7 +124,7 @@ export async function getStaticPaths() {
paths.push({
params: { year: ymd },
props: {
- posts: archive.postsByDate.get(ymd),
+ posts: archive.postsByDate.get(ymd) ?? [],
next: archive.sortedDates?.[i + 1],
previous: archive.sortedDates?.[i - 1],
years: sortedYears,
@@ -139,16 +135,16 @@ export async function getStaticPaths() {
}
return paths;
-}
+}) satisfies GetStaticPaths;
+
+export type Params = InferGetStaticParamsType<typeof getStaticPaths>;
+export type Props = InferGetStaticPropsType<typeof getStaticPaths>;
const title = "Blog";
const description = "Latest articles.";
let { posts, previous, next, years, months, days } = Astro.props;
-posts = posts.sort((a, b) =>
- new Date(b.data.dateCreated).valueOf() -
- new Date(a.data.dateCreated).valueOf()
-);
+posts = posts.sort(sortLastCreated);
const date = posts[0].data.dateCreated as Date;
---